%% Create new schedule for Psychophysics

% File Name | warning: file will be overwritten without prompting
sch = 'Rat_TrainPhase1_NB_Rig_3.mat';
% sch = 'Rat_TrainPhase1_NB_Rig_4.mat';
schDir = 'C:\Behavior\Rat NBN Gap Detection\Schedule Files\';

clear schedule trialdef

%% parameter tags

% for RPvds direct access
schedule.writeparams = {'trial_type~1', ...
    'NoiseDB~1','NoiseCalibration~1', ...
    'NoiseLP~1','NoiseHP~1', ...
    'stim_delay~1','stim_duration~1'};

% use neg values for PA5 index; use 0 (zero) for file
schedule.writemodule = ones(size(schedule.writeparams));
schedule.readparams  = {'trial_type~1','response_code~1','NoiseDB~1','NoiseHP~1'};
schedule.readmodule  = ones(size(schedule.readparams));
schedule.nreps       = 100;
schedule.randomize   = true;
schedule.schedule    = fullfile(schDir,sch);

%% Check yo' self
if length(schedule.writeparams) ~= length(schedule.writemodule)
	error('write params/module lengths differ!');
end

if length(schedule.readparams) ~= length(schedule.readmodule)
	error('read params/module lengths differ!');
end

%% trial defs
clear trialdef

% 0 is stimulus trial, 1 is catch trial
trialdef{1} = {'buddy','trial_type',[0]};
trialdef{2} = {'buddy','trial_type',[70]};
% calibration values are at 1 volt and must be negative here
trialdef{3} = {'buddy','stim',-[90.89 81.32 82.36 81.56]};  % Box 1
% trialdef{3} = {'buddy','stim',-[88.54 80.02 80.6 79.77]};  % Box 2
trialdef{4} = {'buddy','stim',[45255 9513.7 19027.3 28541]};
trialdef{5} = {'buddy','stim',[2000 6727.2 13454.3 20181.5]};
% trialdef{6} = {'randomized',[],[1 1000]};
trialdef{6} = {1};
trialdef{7} = {100};

%% Get Unique Trials
schedule = BHVR_AddTrial(schedule,trialdef);


%% Save
if ~exist(schDir,'dir'), mkdir(schDir); end
save(fullfile(schDir,sch),'schedule');

